import { mapGetters } from 'vuex'

export default {
  computed: {
    ...mapGetters(['pagination']),
    hasData() {
      return !(!this.pageData.items || this.pageData.items.size === 0 ||
        this.pageData.total === 0)
    }
  },
  data() {
    return {
      pageData: {
        items: [],
        total: 0,
        pageSize: 10,
        currentPage: 1
      }
    }
  },
  methods: {
    handleSizeChange(size) {
      console.log(size)
      this.$store.dispatch('ChangePageSize', size).then(() => {
        this.searchData()
      })
    },
    formatSeconds(value) {
      var secondTime = parseInt(value)
      var minuteTime = 0
      var hourTime = 0
      if (secondTime > 60) {
        minuteTime = parseInt(secondTime / 60)
        secondTime = parseInt(secondTime % 60)
        if (minuteTime > 60) {
          hourTime = parseInt(minuteTime / 60)
          minuteTime = parseInt(minuteTime % 60)
        }
      }
      var result = '' + parseInt(secondTime) + '秒'

      if (minuteTime > 0) {
        result = '' + parseInt(minuteTime) + '分' + result
      }
      if (hourTime > 0) {
        result = '' + parseInt(hourTime) + '小时' + result
      }
      return result
    },
    handleCurrentChange(page) {
      this.pageData.currentPage = page
      this.searchData()
    }
  }
}
